<?php 
require_once 'header.inc.php';
if (isset($_POST[submit])) {
	//获得注册信息
	$stuId = $_POST['stuId'];
	$stuName = $_POST['stuName'];
	$stuPwd = $_POST['stuPswd'];
	$stuAge = $_POST['stuAge'];
	$stuGender = $_POST['stuGender'];
	//构造SQL语句
	$sql = 'SELECT * FROM `students` WHERE stuId = :stuId';
	//预处理SQL语句
	$stmt = $pdo->prepare($sql);
	//绑定参数
	$stmt->bindParam(':stuId', $stuId);
	//执行查询
	$stmt->execute();
	//获得返回结果
	$count = $stmt->rowCount();
	if ($count) {
		echo '该学生已经注册,请重新填写信息';
	}
	else {
		$sql = 'INSERT INTO `students` values(:stuId, :stuName, :stuPwd, :stuGender, :stuAge)';
		$stmt = $pdo->prepare($sql);
		$stmt->bindParam(':stuId', $stuId);
		$stmt->bindParam(':stuName', $stuName);
		$stmt->bindParam(':stuPwd', $stuPwd);
		$stmt->bindParam(':stuGender', $stuGender);
		$stmt->bindParam(':stuAge', $stuAge);
		
		$stmt->execute();var_dump($stmt);
		exit();
		//header('Location:login.php');
	}
	
	
}

?>

<div id="register" align="center">
	<div id="registerTitle" style="font-size:24px;font-weight:bold;text-align:center;">
		用户登录
	</div>
	<div id="registerInfo" style="font-size:18px;font-weight:bold;text-align:center">
		<form action="" method="post">
			<p>学号：<input type="text" name="stuId"/></p>
			<p>姓名：<input type="text" name="stuName"/></p>
			<p>密码：&nbsp;<input type="password" name="stuPswd"/></p>
			<p>年龄：<input type="text" name="stuAge"></p>
			<p>性别：&nbsp;&nbsp;&nbsp;&nbsp;
				男<input type="radio" name="stuGender" value="1" />&nbsp;&nbsp;&nbsp;&nbsp;
				女<input type="radio" name="stuGender" value="0" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
			<p><input type="submit" name="submit" value="注册" style="font-size:18px"/></p>
		</form>
	</div>
</div>

<?php 
require_once 'footer.inc.php';
?>